<?

include_once "accesscontrol.php";


if(isset($ok) && $ok == 'Click Here to Apply')
{
	$q1 = "select CompanyEmail from job_employer_info where ename = \"$_POST[ename]\"";
	$r1 = mysql_query($q1) or die(mysql_error());
	$a1 = mysql_fetch_array($r1);

	$url = "http://$_SERVER[HTTP_HOST]$dir/employers/EmployerView.php?uname=$uname";

        $q2 = "select fname, job_seeker_email, rTitle from job_seeker_info where uname = \"$_SESSION[uname]\" ";
        $r2 = mysql_query($q2) or die(mysql_error());
        $a2 = mysql_fetch_array($r2);
	
	if(empty($a2[rTitle]))
	{
		echo "<br><br><br><center><span class=TNA>You do not have a resume yet. <br> Please, <a class=TNA href=build_resume.php> build </a> one and then apply for the job.</span></center>";
		include_once('../footer.php');
		exit;
	}

	$qui = "insert into job_aplicants set job_id = \"$_POST[job_id]\", aplicant = \"$_SESSION[uname]\"";
	$rui = mysql_query($qui) or die(mysql_error());

	$from = "From: $a2[0] <$a2[1]>";
	$subject = "New job applicant";
	$message = "A job seeker has applied for your job offer. To review the aplicant's resume, go to this address:\n $url\n\n You can access this information from Employers menu/Manage Jobs and then click on the link \"view aplicant list\" for each job offer.";
	mail($a1[0], $subject, $message, $from);

echo "<br><br><br><center><span class=BlackLink>Your aplication was sent to the employer.</span></center>";
}
elseif(isset($friend) && $friend == 'Send to a friend')
{
	$url = "http://$_SERVER[HTTP_HOST]$dir/jobseekers/FriendView.php?job_id=$_POST[job_id]";
?>

<script>

function CheckFriend() {

	if(!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.fr1.femail.value))
	{
		alert("Invalid E-mail Address! Please re-enter.");
		document.fr1.femail.value="";
		document.fr1.femail.focus();
		return false;
	}
}

</script>

<br>
	<form action=Friend2.php method=post onsubmit="return CheckFriend();" name=fr1>
	<table align=center class=BlackLink>
	<caption align=center class=HeaderClass>Send this job to a friend!</caption>
		<tr>
			<td align=right>Friend's email:</td>
			<td><input type=text name=femail size=31></td>
		</tr>
		
		<tr>
			<td valign=top align=right>Message:</td>
			<td><textarea rows=4 cols=30 name=fmessage>I find a great Job Offer at <?=$_SERVER[HTTP_HOST]?>. Go to this URL to find out more. <?=$url?> </textarea></td>
		</tr>

		<tr>
		<td colspan=2 align=center>
			<input type=hidden name=job_id value="<?=$job_id?>">
			<input type=submit name=submit value=Send>
		</td>
		</tr>
	</table>
<?	
}
?>
<? include_once('../footer.php'); ?>